package com.zjh.controller;

import com.zjh.dao.sysUserDao;
import com.zjh.service.sysUserService;
import com.zjh.utils.Response;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(tags = "用户请求处理Controller")
@RequestMapping("/sysusr")
public class sysUserController {

    @Autowired
    sysUserService service;

    @GetMapping("/all")
    @ApiOperation(value = "查询所有用户信息")
    public Response<List<sysUserDao>> getAllUsr()
    {
        List<sysUserDao> users =  service.getAllUsers();
        return Response.success(users);
    }

    @ApiOperation(value = "添加用户", notes = "添加一个用户,传入用户名和地址")
    @PostMapping("/add")
    public Response insertUsr(@RequestBody sysUserDao usr)
    {
        try {
            service.addUser(usr);
            return Response.success("添加用户成功");
        }
        catch (Exception e)
        {
            return Response.success("添加用户失败" + e.getMessage());
        }

    }

    @GetMapping("/queryone")
    public Response<sysUserDao> queryByUsername(@RequestParam("username") String username)
    {
        sysUserDao usr = service.getuserByUsername(username);
        return Response.success(usr);
    }
}
